/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * Projects
 * Copyright (C) Arnaud Duval 2011 <arnaud.duval@gmail.com>
 *
 * Projects is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Projects is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "user-day-edit-dialog.hpp"

///@brief Constructor
///@param titre Title of the window
///@param parent Pointer to the parent window
///@param lastDay UserDay initializing the values
UserDayEditDialog::UserDayEditDialog(std::string titre, Gtk::Window *parent,
                            UserDay lastDay)
{
    ///@brief Set the border width of the window
    set_border_width(0);
    ///@brief set the labels text
    FillLabels();

    ///@brief Settings the parameters for the entry of date and time
    dateEntry.SetPrintFormat("dd/mm/yyyy");
    timeEntry.SetPrintFormat("hh:nn");

    ///@brief Setting HBox for weight edition
    weightHBox.pack_start(weightLabel, Gtk::PACK_EXPAND_WIDGET);
    weightHBox.pack_start(weightEntry, Gtk::PACK_SHRINK);

    ///@brief Setting HBox for height edition
    heightHBox.pack_start(heightLabel, Gtk::PACK_EXPAND_WIDGET);
    heightHBox.pack_start(heightEntry, Gtk::PACK_SHRINK);

    ///@brief Setting HBox for rest HR edition
    restHRHBox.pack_start(restHRLabel, Gtk::PACK_EXPAND_WIDGET);
    restHRHBox.pack_start(restHREntry, Gtk::PACK_SHRINK);
    restHREntry.NotDisplayIfZero();

    ///@brief Setting HBox for max HR edition
    maxHRHBox.pack_start(maxHRLabel, Gtk::PACK_EXPAND_WIDGET);
    maxHRHBox.pack_start(maxHREntry, Gtk::PACK_SHRINK);
    maxHREntry.NotDisplayIfZero();

    ///@brief Setting the HBox for humor index edition
    humorHBox.pack_start(humorLabel, Gtk::PACK_EXPAND_WIDGET);
    humorHBox.pack_start(humorCBT, Gtk::PACK_SHRINK);

    ///@brief Setting the HBox for sensations index edition
    sensationsHBox.pack_start(sensationsLabel, Gtk::PACK_EXPAND_WIDGET);
    sensationsHBox.pack_start(sensationsCBT, Gtk::PACK_SHRINK);

    ///@brief Filling humor index selector
    std::string humorDescriptors[MAX_HUMOR_INDEX - MIN_HUMOR_INDEX + 1] = {HUMOR_DESCR};
    for(unsigned int i = 0 ; i <=  MAX_HUMOR_INDEX - MIN_HUMOR_INDEX ; i++)
        humorCBT.append_text(humorDescriptors[i]);

    ///@brief Filling sensations index selector
    std::string sensationsDescriptors[MAX_SENSATIONS_INDEX - MIN_SENSATIONS_INDEX + 1] = {SENSATIONS_DESCR};
    for(unsigned int i = 0 ; i <= MAX_SENSATIONS_INDEX - MIN_SENSATIONS_INDEX ; i++)
        sensationsCBT.append_text(sensationsDescriptors[i]);


    ///@brief Adding all boxes to the main VBox
    get_vbox()->pack_start(dateHBox, Gtk::PACK_SHRINK);
    get_vbox()->pack_start(timeHBox, Gtk::PACK_SHRINK);
    get_vbox()->pack_start(weightHBox, Gtk::PACK_SHRINK);
    get_vbox()->pack_start(heightHBox, Gtk::PACK_SHRINK);
    get_vbox()->pack_start(humorHBox, Gtk::PACK_SHRINK);
    get_vbox()->pack_start(sensationsHBox, Gtk::PACK_SHRINK);
    get_vbox()->pack_start(restHRHBox, Gtk::PACK_SHRINK);
    get_vbox()->pack_start(maxHRHBox, Gtk::PACK_SHRINK);
    
    


    ///@brief Addiction of button for cancel or validation
    add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);

    show_all();
}

///@brief Destructor
UserDayEditDialog::~UserDayEditDialog()
{

}

///@brief Update current UserDay with value in the form
void UserDayEditDialog::UpdateUserDay()
{
    currentDay.SetWeight(weightEntry.GetValue());
    currentDay.SetHeight(heightEntry.GetValue());
    currentDay.SetHumor(humorCBT.get_active_row_number());
    currentDay.SetSensations(sensationsCBT.get_active_row_number());
    ///TODO : traiter les valeurs humor et sensations
    currentDay.SetRestHR(restHREntry.GetValue());
    currentDay.SetMaxHR(maxHREntry.GetValue());
}

///@brief Update the content of the dialog with current user day values
void UserDayEditDialog::Update()
{
    heightEntry.SetValue(currentDay.GetHeight());
}

///@brief Return the current UserDay
UserDay UserDayEditDialog::GetUserDay()
{
    UpdateUserDay();
    return currentDay;
}

///@brief Set the date of the current user day
///@param theDate date to be set
void UserDayEditDialog::SetDate(DateTime theDate)
{
    ///TODO : mettre a jour la date affichée
    currentDay.SetDate(theDate);
}

///@brief Fill the labels
void UserDayEditDialog::FillLabels()
{
    dateLabel.set_text("Date :");
    timeLabel.set_text("Heure :");
    weightLabel.set_text("Poids :");
    heightLabel.set_text("Taille :");
    humorLabel.set_text("Humeur :");
    sensationsLabel.set_text("Sensations :");
    restHRLabel.set_text("FC au repos :");
    maxHRLabel.set_text("FC max :");

}
